using System.Collections.Generic;
using System.Linq;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.Skill;
using TrainingManagement.api.Models.Data.CRUD.TrainingRecord;

namespace TrainingManagement.api.Models.BusinessLogic.TrainingRecord
{
    public class TrainingRecordSelectOperation : BusinessOperation<int, List<BusinessObjects.TrainingRecord>>
    {
        readonly TrainingRecordSelectByEmployeeIdDataSource _recordSource = new TrainingRecordSelectByEmployeeIdDataSource();
        readonly SkillSelectDataSource _skillSource = new SkillSelectDataSource();

        public override List<BusinessObjects.TrainingRecord> Run(int input)
        {
            //get records
            var records = _recordSource.Execute(input);

            //fill in skills
            foreach (var trainingRecord in records)
            {
                trainingRecord.Skill = _skillSource.Execute(trainingRecord.SkillId).FirstOrDefault();
            }
            return records;
        }
    }
}